/*
	FileName : JT_C_Power_Track.h
	Description :
	Created on 2018.10.17 by WFL.
	Revision History:
*/
#ifndef  __JT_C_POWER_TRACK_20181017__
#define  __JT_C_POWER_TRACK_20181017__
//
#include "stdint.h"
//----------------------------------------------------
#define POWER_STATES_STARTUP	0
#define POWER_STATES_LOW		1
#define POWER_STATES_HIGH		2
//-------------------------------
#define POWER_DERECTION_STARTUP	0
#define POWER_DERECTION_RISE	1
#define POWER_DERECTION_FALL	2
#define POWER_DERECTION_POPPLE	3
//-------------------------------
#define ADC_SAMPLE_RATE			12500
#define POWER_STABLE_DELAY		(10 * ADC_SAMPLE_RATE / 1000)
//-------------------------------
//Vdet = 963mV for V12, and 1200 for V11----- Vbat = 4.15 * Vdet -0.72525 --------
#define POWER_HIGH_LEVEL		(4095 * (100 * 3800 + 72525) / 3300 / 415)	//3.8V
#define POWER_LOW_LEVEL			(4095 * (100 * 3200 + 72525) / 3300 / 415)	//3.2V

//-------------------------------
#define POWER_DERECTION_CASE_LEN	10
#define POWER_DERECTION_SECTION_LEN	(40 * ADC_SAMPLE_RATE / 1000)
//----------------------------------------
typedef struct{
	uint8_t		states;					///
	uint8_t		statesChangeCnt;		///
	uint16_t	currentVal;				///
	uint32_t	staySameCounter;		///
	//-------------------------------------
	uint8_t		powerDropFound;			///
	//-------------------------------------
	uint8_t		direction;				///	
	uint16_t	dirChangeCnt;			///
	uint32_t	dir_sum[POWER_DERECTION_CASE_LEN];
	uint16_t	dir_sum_cnt;

}JTC_POWER_TRACK, *pJTC_POWER_TRACK;
//--------------------------------------------------------------------------
extern JTC_POWER_TRACK JTC_power_t;
//-------------------------
uint8_t JTC_POWER_TRACK_init(JTC_POWER_TRACK *power_t);
uint8_t JTC_POWER_TRACK_handle(JTC_POWER_TRACK *power_t,uint16_t powVal);
uint8_t JTC_POWER_TRACK_has_drop(JTC_POWER_TRACK *power_t);
//--------------------------------------------------------------------------
#endif




///EOF


